const Router = require('koa-router');
const foster = new Router();
const sqldata = require('./sqldata');

// 添加寄养作品
foster.post('/foster',async (ctx) => {
    let mydata = await new Promise((resolve, reject)=>{
        let val=ctx.request.body;
        console.log(val)
        const sqlLang =`INSERT INTO foster (Pid,Uid,Pname,Page,Pvarie,Pinject,Ftime,Uphone,Uarea,Pintroduction,Photo) VALUES ('${val.Pid}', '${val.Uid}', '${val.Pname}', '${val.Page}', '${val.Pvarie}', '${val.Pinject}', '${val.Ftime}', '${val.Uphone}', '${val.Uarea}', '${val.Pintroduction}','${val.Photo}')`;
        return sqldata(sqlLang, (err, data)=>{
            if(err) reject(err);
            resolve(data);	// 返回拿到的数据
        })
    })
    ctx.body=mydata;
})

module.exports = foster;